﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//,return (value +aa-1)&~(aa-1)
// value>0, value + aa - 1
// value<0, value + aa - 1

// aa<0, value + aa - 1
class ProgramZhangqu1
{

    static void MainZhangqu1(string[] args)
    {


        //int res = Zhangqusol(7, 5);
        int val = 19;
        int aa = 7;
        //for (int i = -10; i < aa; i++) {

        //    //Console.WriteLine(Zhangqusol(val, i));
        //    Console.WriteLine(~(i-1));
        //}
        int res = Zhangqusol(val, aa);
        int res2 = Zhangqusol2(val, aa);
        Console.WriteLine(res);
        //Console.WriteLine(res2);
    }


    public static  int Zhangqusol(int value, int aa)
    {

        //Console.WriteLine(value + aa - 1);
        //Console.WriteLine(~(aa - 1));//这个是取相反数的操作
        //Console.WriteLine((aa - 1));//这个是取相反数的操作
        //Console.WriteLine(Convert.ToString(aa - 1, 2));
        //Console.WriteLine(Convert.ToString((~(aa - 1)), 2));

        return (value + aa - 1) & ~(aa - 1);
    }
      public static  int Zhangqusol2(int value, int aa)
    {


        //return (value + aa - 1) & (-aa);
        return (value + aa - 1);


        //return  (-aa) & (aa - 1);
        //return  (-aa) & (value);
    }
    public static int Zhangqusol3(int value, int aa)
    {

        return (value + aa - 1) & ~(aa - 1);

    }
}
